/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.tfile;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>Project: jse2303 - FileServer</p>
 * <p>Powered by webrx On 2023-07-26 14:00:46</p>
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class FileServer {
    public static void main(String[] args) {
        List<Socket> sss = new ArrayList<>();
        try {
            ServerSocket ss = new ServerSocket(8888);
            while (true) {
                try {
                    Socket c = ss.accept();
                    sss.add(c);
                    InputStream is = new FileInputStream("c.jpg");
                    OutputStream os = c.getOutputStream();
                    byte[] buf = new byte[1024];
                    int len = 0;
                    while ((len = is.read(buf)) > 0) {
                        os.write(buf, 0, len);
                    }
                    is.close();
                    os.close();
                    c.close();
                } catch (Exception e) {
                }
            }
        } catch (Exception e) {

        }
    }
}
